package com.love.cloud.auth.tokengranter;

import com.love.cloud.common.core.constant.SecurityConstants;
import com.love.cloud.common.security.token.MyAuthenticationToken;
import com.love.cloud.common.security.token.PhoneOpenCodeAuthenticationToken;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.oauth2.provider.ClientDetailsService;
import org.springframework.security.oauth2.provider.OAuth2RequestFactory;
import org.springframework.security.oauth2.provider.token.AuthorizationServerTokenServices;

import java.util.Map;

/**
 * 自定义手机号和openCodeToken授予者
 * @author hongdongqu
 */
public class PhoneOpenCodeCustomTokenGranter extends AbstractCustomTokenGranter {

    public PhoneOpenCodeCustomTokenGranter(AuthenticationManager authenticationManager, AuthorizationServerTokenServices tokenServices, ClientDetailsService clientDetailsService, OAuth2RequestFactory requestFactory) {
        super(authenticationManager,tokenServices, clientDetailsService, requestFactory, SecurityConstants.GRANT_TYPE_CUSTOM_PHONE_OPEN_CODE);
    }

    @Override
    protected MyAuthenticationToken getAuthenticationToken(Map<String, String> parameters) {
        String  principal= parameters.get("phone");
        String credentials = parameters.get("openCode");
        return new PhoneOpenCodeAuthenticationToken(principal,credentials);
    }
}
